#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>

void ftype_switch(struct stat *buf) {
  switch(buf->st_mode & S_IFMT) {
  case S_IFSOCK:   
    fputs("socket\n", stdout);
    break;
  case S_IFLNK:
    fputs("symbolic link\n", stdout);
    break;
  case S_IFREG:
    fputs("regular file\n", stdout); break;
  case S_IFBLK:
    fputs("block device\n", stdout);
    break;
  case S_IFDIR:
    fputs("directory\n", stdout);
    break;
  case S_IFCHR:
    fputs("character device\n", stdout);
    break;
  case S_IFIFO:
    fputs("FIFO\n", stdout);
    break;
  }
}

int main(void)
{
  struct stat buf;
  int res = stat(".", &buf);
  if(res) return res;
  ftype_switch(&buf);
  res = lstat(".", &buf);
  if(res) return res;
  ftype_switch(&buf);
  int fd = open(".", O_RDONLY); 
  res = fstat(fd, &buf);
  if(res) return res;
  ftype_switch(&buf);
  return 0;
  
}
